package com.face.server.controller;

import com.face.RespMsg;
import com.face.server.entity.Admin;
import com.face.server.entity.EventLog;
import com.face.server.repository.EventLogRepository;
import com.face.server.service.impl.EventLogService;
import com.util.DateUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.text.ParseException;
import java.util.Calendar;
import java.util.Date;
import java.util.List;


@Controller
@RequestMapping("event")
public class EventLogController {

    @Autowired
    EventLogRepository eventLogRepository;

    @Autowired
    SimpMessagingTemplate messagingTemplate;

    @Autowired
    EventLogService eventLogService;

    @GetMapping("index")
    String index() {
        return "socket";
    }

    @PostMapping("log")
    @ResponseBody
    String log(String eventLog) {
        messagingTemplate.convertAndSend("/topic/log", eventLog);
        return eventLog;
    }

    @MessageMapping("say")
    @SendTo("/topic/log")
    public String ask(String message) {
        System.out.println(message);
        return message;
    }

    @GetMapping
    RespMsg all() {
        return RespMsg.build(eventLogRepository.findAll());
    }

}
